package cn.itsource._04_direct;

import cn.itsource._01_hello_world.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

//消息发送者
public class Send {

    //交换机的名字
    public static final String NAME_EXCHANGE_DIRECT = "name_exchange_direct";

    public static void main(String[] args) throws Exception {
        //1.通过连接工具创建链接对象
        Connection connection = ConnectionUtil.getConnection();

        //2.创建通道
        Channel channel = connection.createChannel();

        //4.创建交换机:定向
        channel.exchangeDeclare(NAME_EXCHANGE_DIRECT, BuiltinExchangeType.DIRECT);

        //5.发送消息:使用默认的交换机 - 不创建交换机
        String message = "A hello world message";
        //交换机(默认)，队列名(routingkey),属性参数，消息内容
        channel.basicPublish(NAME_EXCHANGE_DIRECT,"delete",null,message.getBytes());
        System.out.println("消息发送完毕："+message);
    }

}
